package Eventer;

import UserModule.FinalUser;
import UserModule.GroupType;
import UserModule.UserGroup;

import java.util.ArrayList;
import java.util.Objects;

public class Eventlisteners {
    ArrayList<Events> Eventlistener(ArrayList<Events> events, FinalUser user, UserGroup allUserGroup) {
        int UserID = user.basicUser.userID;
        /*先筛选UserGroupID是不是Admin或者是SUP*/
        boolean UserIsAdmin = false;
        ArrayList<Object> AdminGroupID = new ArrayList<>();
        if (allUserGroup.groupType.equals(GroupType.Admin) || allUserGroup.groupType.equals(GroupType.SuperAdmin))
        {
            AdminGroupID.add(allUserGroup.groupID);
        }
        for (Object o : AdminGroupID) {
            int groupID = (int) o;
            if (user.userInfo.UserInGroupID == groupID) {
                UserIsAdmin = true;
            }
        }
        ArrayList<Events> ThisUserEvent = new ArrayList<>();
        for (Events event : events) {
            if (event.ToWho.equals(EventTargetTo.Everyone)) {
                ThisUserEvent.add(event);
                break;
            } else if (event.UserID == UserID) {
                ThisUserEvent.add(event);
                break;
            } else if (UserIsAdmin) {
                ThisUserEvent.add(event);
            }
        }
        return ThisUserEvent;
    }
}
